-
Notifications
You must be signed in to change notification settings - Fork 1.4k
clai: Add ability to continue last conversation #2257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
PR Change SummaryAdded the ability to continue the last conversation in the clai CLI tool.
Modified Files
How can I customize these reviews?Check out the Hyperlint AI Reviewer docs for more information on how to customize the review. If you just want to ignore it on this PR, you can add the Note specifically for link checks, we only check the first 30 links in a file and we cache the results for several hours (for instance, if you just added a page, you might experience this). Our recommendation is to add |
|
I don't know why coverage is not 100%( |
|
Hi @uriyyo 👋 Good to see you here. :) Instead of just continuing the last conversation, can we select the session we want to continue? It would be nice to have a drop-down where the user could select the session. We can use the prompt-toolkit package for it. |
@Kludex Long time no see, good to see you again! |
00b521a to
2990a68
Compare
@Kludex Sounds interesting, any suggestions on how it should look like? I imagine adding input query slugify that will assign session specific slug, and then you can continue session based on a generated slug. For instance if we are doing query like this: clai "How to start thread in python?"Slug might look like this - And then you can continue this session: clai "and how can I start 10 threads" --session python-start-threadAlso, it makes sense to add Where: I still would love to have ability to continue just last conversation, but it can be implemented around sessions. |
2990a68 to
8884141
Compare
8884141 to
cf3b691
Compare
I'm sorry. I thought I had replied. I think we can store the session with an uuid as file name, and then when resuming, we should see the first message truncated as part of that selection. This selection should be using prompt-toolkit. |
|
Feel free to reach me on our Slack, in case I take more than a day to reply. |
|
@uriyyo Are you still interested in working on this? |
|
@DouweM Yup, I will try to wrap it all this week |
|
This PR is stale, and will be closed in 3 days if no reply is received. |
|
Hi all, sorry for no response. Does it still make sense for me to work on this feature? If yes, I will try to do it ASAP |
|
@uriyyo Yes go for it! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a new feature to continue the last conversation in the Pydantic AI CLI instead of starting fresh each time. The key functionality enables users to use the -c or --continue flag to resume their previous conversation.
- Added conversation persistence to JSON files in the
.pydantic-aidirectory - Implemented
-c/--continueCLI flag to resume previous conversations - Added error handling for corrupted conversation files
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 9 comments.
| File | Description |
|---|---|
| pydantic_ai_slim/pydantic_ai/_cli.py | Implemented conversation storage/loading functions and integrated them into the CLI workflow with the new --continue flag |
| tests/test_cli.py | Added tests for the continue conversation feature and updated existing test assertions to include the new history parameter |
| clai/README.md | Updated CLI usage documentation to include the new -c/--continue flag option |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
pydantic_ai_slim/pydantic_ai/_cli.py
Outdated
| assert agent_run.result is not None | ||
| return agent_run.result.all_messages() | ||
| result_messages = agent_run.result.all_messages() | ||
| store_last_conversation(result_messages, config_dir) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we restructure this a bit to not repeat these 2 lines?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, tried to fix it
|
Hi @DouweM, I tried to add fixes. Could you please take a look? If everything is good, I will add tests. |
| -l, --list-models List all available models and exit | ||
| -t [CODE_THEME], --code-theme [CODE_THEME] | ||
| Which colors to use for code, can be "dark", "light" or any theme from pygments.org/styles/. Defaults to "dark" which works well on dark terminals. | ||
| -c [CONTINUE_], --continue [CONTINUE_] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the readme, this should really say PATH rather than CONTINUE_
| -t [CODE_THEME], --code-theme [CODE_THEME] | ||
| Which colors to use for code, can be "dark", "light" or any theme from pygments.org/styles/. Defaults to "dark" which works well on dark terminals. | ||
| -c [CONTINUE_], --continue [CONTINUE_] | ||
| Continue last conversation, if any, instead of starting a new one. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs updating now that we support an optional path
| Which colors to use for code, can be "dark", "light" or any theme from pygments.org/styles/. Defaults to "dark" which works well on dark terminals. | ||
| -c [CONTINUE_], --continue [CONTINUE_] | ||
| Continue last conversation, if any, instead of starting a new one. | ||
| --store STORE Store the last conversation to the specified path instead of the default location. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PATH would be better than STORE here as well
| '--continue', | ||
| nargs='?', | ||
| dest='continue_', | ||
| const=str(PYDANTIC_AI_HOME / LAST_CONVERSATION_FILENAME), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm so we're not respecting the config_dir anymore? Could we fix that
Hi,
Thanks for
clai, I'm using it all the time 🙌One minor feature that I miss is the ability to continue the last conversation, cause my usage looks like this:
So now it will be possible:
I'm not sure if
-cis a good option name, as it is usually used for configuration, so maybe-r/--resumewould be a better option. I will be happy to update the implementation with better naming.